package com.tnsw.noxnox;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.widget.ImageView;

public class MyDragShadowBuilder extends DragShadowBuilder {
	
    // The drag shadow image, defined as a drawable thing
    private static Drawable shadow;

    // Defines the constructor for myDragShadowBuilder
    public MyDragShadowBuilder(View v) {

    	// Stores the View parameter passed to myDragShadowBuilder.
    	super(v);

    	// Creates a draggable image that will fill the Canvas provided by the system.
        shadow = new ColorDrawable(Color.LTGRAY);
    }
    
    @Override
    public void onProvideShadowMetrics (Point size, Point touch) {
        // Defines local variables
		Drawable d = ((ImageView) this.getView()).getDrawable();
		BitmapDrawable bd = (BitmapDrawable) d;
		Bitmap b = bd.getBitmap();
		int width = bd.getBitmap().getWidth();
		int height = bd.getBitmap().getHeight();
        
        super.onProvideShadowMetrics(size, touch);
        // Sets the size parameter's width and height values. These get back to the system
        // through the size parameter.
        //size.set(width/2, height/2);
        
        
        // Sets the width of the shadow to half the width of the original View
        width = getView().getWidth() / 2;

        // Sets the height of the shadow to half the height of the original View
        height = getView().getHeight() / 2;

        // The drag shadow is a ColorDrawable. This sets its dimensions to be the same as the
        // Canvas that the system will provide. As a result, the drag shadow will fill the
        // Canvas.
        shadow.setBounds(0, 0, width, height);



        // Sets the touch point's position to be in the middle of the drag shadow
        touch.set(width / 2, height / 2);
        
        
    }
    
    @Override
    public void onDrawShadow(Canvas canvas) {

        // Draws the ColorDrawable in the Canvas passed in from the system.
        // shadow.draw(canvas);
    	//super.onDrawShadow(canvas);

		Drawable d = ((ImageView) this.getView()).getDrawable();
		BitmapDrawable bd = (BitmapDrawable) d;
		Bitmap b = bd.getBitmap();
		int width = bd.getBitmap().getWidth();
		int height = bd.getBitmap().getHeight();
    	
		canvas.drawBitmap(b, 0, 0, null);
    	
    }
}
